home *** CD-ROM | disk | FTP | other *** search
Wrap
RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhMMMMuuuullllttttiiiiSSSSeeeetttt((((3333CCCC++++++++)))) RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhMMMMuuuullllttttiiiiSSSSeeeetttt((((3333CCCC++++++++)))) NNNNaaaammmmeeee RWTValHashMultiSet<T,H,EQ> - Rogue Wave library class SSSSyyyynnnnooooppppssssiiiissss #include <rw/tvhasht.h> RWTValHashMultiSet<T,H,EQ> PPPPlllleeeeaaaasssseeee NNNNooootttteeee!!!! IIIIffff yyyyoooouuuu hhhhaaaavvvveeee tttthhhheeee SSSSttttaaaannnnddddaaaarrrrdddd CCCC++++++++ LLLLiiiibbbbrrrraaaarrrryyyy,,,, uuuusssseeee tttthhhheeee iiiinnnntttteeeerrrrffffaaaacccceeee ddddeeeessssccccrrrriiiibbbbeeeedddd hhhheeeerrrreeee.... OOOOtttthhhheeeerrrrwwwwiiiisssseeee,,,, uuuusssseeee tttthhhheeee iiiinnnntttteeeerrrrffffaaaacccceeee ffffoooorrrr RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhTTTTaaaabbbblllleeee described in Appendix A. DDDDeeeessssccccrrrriiiippppttttiiiioooonnnn This class maintains a collection of values, which are stored according to a hash object of type HHHH. HHHH must offer a hash function for elements of type TTTT via a public member uuuunnnnssssiiiiggggnnnneeeedddd lllloooonnnngggg ooooppppeeeerrrraaaattttoooorrrr(((())))((((ccccoooonnnnsssstttt TTTT&&&& xxxx)))) ccccoooonnnnsssstttt Objects within the collection will be grouped together based on an equality object of type EEEEQQQQ. EEEEQQQQ must ensure this grouping via public member bbbboooooooollll ooooppppeeeerrrraaaattttoooorrrr(((())))((((ccccoooonnnnsssstttt TTTT&&&& xxxx,,,, ccccoooonnnnsssstttt TTTT&&&& yyyy)))) ccccoooonnnnsssstttt which should return ttttrrrruuuueeee if xxxx and yyyy are equivalent, ffffaaaallllsssseeee otherwise. RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhMMMMuuuullllttttiiiiSSSSeeeetttt<<<<TTTT,,,,HHHH,,,,EEEEQQQQ>>>> may contain multiple items that compare equal to each other. (RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhSSSSeeeetttt<<<<TTTT,,,,HHHH,,,,EEEEQQQQ>>>> will not accept an item that compares equal to an item already in the collection.) PPPPeeeerrrrssssiiiisssstttteeeennnncccceeee Isomorphic EEEExxxxaaaammmmpppplllleeee // // tvhmsstr.cpp // #include <rw/tvhasht.h> #include <rw/cstring.h> #include <iostream.h> struct silly_hash{ unsigned long operator()(RWCString x) const { return x.length() * (long)x[0]; } }; main(){ RWTValHashMultiSet<RWCString,silly_hash,equal_to<RWCString> > set1; RWTValHashMultiSet<RWCString,silly_hash,equal_to<RWCString> > set2; PPPPaaaaggggeeee 1111 RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhMMMMuuuullllttttiiiiSSSSeeeetttt((((3333CCCC++++++++)))) RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhMMMMuuuullllttttiiiiSSSSeeeetttt((((3333CCCC++++++++)))) set1.insert("one"); set1.insert("two"); set1.insert("three"); set1.insert("one"); // OK: duplicates allowed set1.insert("one"); cout << set1.entries() << endl; // Prints "5" set2.insert("one"); set2.insert("five"); set2.insert("one"); cout << ((set1.isEquivalent(set2)) ? "TRUE" : "FALSE") << endl; // Prints "FALSE" set2.intersection(set1); set1.clear(); cout << set1.entries() << endl; // Prints "0" cout << set2.entries() << endl; // Prints "2" return 0; RRRReeeellllaaaatttteeeedddd CCCCllllaaaasssssssseeeessss } Class RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhSSSSeeeetttt<<<<TTTT,,,,HHHH,,,,EEEEQQQQ>>>> offers the same interface to a collection that will not accept multiple items that compare equal to each other. Class rrrrwwww____hhhhaaaasssshhhhmmmmuuuullllttttiiiisssseeeetttt<<<<TTTT,,,,HHHH,,,,EEEEQQQQ>>>> is the C++-standard compliant collection that serves as the underlying implementation for RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhMMMMuuuullllttttiiiiSSSSeeeetttt<<<<TTTT,,,,HHHH,,,,EEEEQQQQ>>>>. PPPPuuuubbbblllliiiicccc TTTTyyyyppppeeeeddddeeeeffffssss typedef rw_hashmultiset<T,H,EQ> container_type; typedef container_type::iterator iterator; typedef container_type::const_iterator const_iterator; typedef container_type::size_type size_type; typedef T value_type; typedef T& reference; typedef const T& const_reference; PPPPuuuubbbblllliiiicccc CCCCoooonnnnssssttttrrrruuuuccccttttoooorrrrssss RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhMMMMuuuullllttttiiiiSSSSeeeetttt<<<<TTTT,,,,HHHH,,,,EEEEQQQQ>>>> (size_type sz = 1024,const H& h = H(),const EQ& eq = EQ()); Constructs an empty set. The underlying hash table representation will have sssszzzz buckets, will use hhhh as its hashing function and will use eeeeqqqq to determine equivalence between elements. RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhMMMMuuuullllttttiiiiSSSSeeeetttt<<<<TTTT,,,,HHHH,,,,EEEEQQQQ>>>>(const rw_hashmultiset<T,H,EQ>& s); Constructs a set by copying all elements of ssss. PPPPaaaaggggeeee 2222 RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhMMMMuuuullllttttiiiiSSSSeeeetttt((((3333CCCC++++++++)))) RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhMMMMuuuullllttttiiiiSSSSeeeetttt((((3333CCCC++++++++)))) RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhMMMMuuuullllttttiiiiSSSSeeeetttt<<<<TTTT,,,,HHHH,,,,EEEEQQQQ>>>>(const RWTValHashMultiSet<T,H,EQ>&); Copy constructor. RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhMMMMuuuullllttttiiiiSSSSeeeetttt<<<<TTTT,,,,HHHH,,,,EEEEQQQQ>>>> (const H& h,size_type sz = RWDEFAULT_CAPACITY); Creates an empty hashed multi-set which uses the hash object hhhh and has an initial hash table capacity of sssszzzz. RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhMMMMuuuullllttttiiiiSSSSeeeetttt<<<<TTTT,,,,HHHH,,,,EEEEQQQQ>>>>(const T* first,const T* last,size_type sz = 1024,const H& h = H(),const EQ& eq = EQ()); Constructs a set by copying elements from the array of TTTTs pointed to by ffffiiiirrrrsssstttt, up to, but not including, the element pointed to by llllaaaasssstttt. The underlying hash table representation will have sssszzzz buckets, will use hhhh as its hashing function and will use eeeeqqqq to determine equivalence between elements. PPPPuuuubbbblllliiiicccc MMMMeeeemmmmbbbbeeeerrrr OOOOppppeeeerrrraaaattttoooorrrrssss RWTValHashMultiSet<T,H,EQ>& ooooppppeeeerrrraaaattttoooorrrr====(const RWTValHashMultiSet<T,H,EQ>& s); RWTValHashMultiSet<T,H,EQ>& ooooppppeeeerrrraaaattttoooorrrr====(const rw_hashmultiset<T,H,EQ>& s); Destroys all elements of self and replaces them by copying all elements of ssss. bool ooooppppeeeerrrraaaattttoooorrrr========(const RWTValHashMultiSet<T,H,EQ>& s) const; bool ooooppppeeeerrrraaaattttoooorrrr========(const rw_hashmultiset<T,H,EQ>& s) const; Returns ttttrrrruuuueeee if self compares equal to ssss, otherwise returns ffffaaaallllsssseeee. Two collections are equal if both have the same number of entries, and iterating through both collections produces, in turn, individual elements that compare equal to each other. PPPPuuuubbbblllliiiicccc MMMMeeeemmmmbbbbeeeerrrr FFFFuuuunnnnccccttttiiiioooonnnnssss void aaaappppppppllllyyyy(void (*fn)(const_reference,void*), void* d) const; Applies the user-defined function pointed to by ffffnnnn to every item in the collection. This function must have prototype: PPPPaaaaggggeeee 3333 RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhMMMMuuuullllttttiiiiSSSSeeeetttt((((3333CCCC++++++++)))) RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhMMMMuuuullllttttiiiiSSSSeeeetttt((((3333CCCC++++++++)))) void yourfun(const_reference a, void* d); Client data may be passed through parameter dddd. iterator bbbbeeeeggggiiiinnnn(); const_iterator bbbbeeeeggggiiiinnnn() const; Returns an iterator positioned at the first element of self. size_type ccccaaaappppaaaacccciiiittttyyyy() const; Returns the number of buckets(slots) available in the underlying hash representation. See rrrreeeessssiiiizzzzeeee below. void cccclllleeeeaaaarrrr(); Clears the collection by removing all items from self. Each item will have its destructor called. bool ccccoooonnnnttttaaaaiiiinnnnssss(const_reference a) const; Returns ttttrrrruuuueeee if there exists an element tttt in self that compares equal to aaaa, otherwise returns ffffaaaallllsssseeee. bool ccccoooonnnnttttaaaaiiiinnnnssss(bool (*fn)(const_reference,void*), void* d) const; Returns ttttrrrruuuueeee if there exists an element tttt in self such that the expression ((((((((****ffffnnnn))))((((tttt,,,,dddd)))))))) is ttttrrrruuuueeee, otherwise returns ffffaaaallllsssseeee. ffffnnnn points to a user-defined tester function which must have prototype: PPPPaaaaggggeeee 4444 RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhMMMMuuuullllttttiiiiSSSSeeeetttt((((3333CCCC++++++++)))) RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhMMMMuuuullllttttiiiiSSSSeeeetttt((((3333CCCC++++++++)))) bool yourTester(const_reference a, void* d); Client data may be passed through parameter dddd. void ddddiiiiffffffffeeeerrrreeeennnncccceeee(const RWTValHashMultiSet<T,H,EQ>& s); Sets self to the set-theoretic difference given by ((((sssseeeellllffff ---- ssss)))). iterator eeeennnndddd(); const_iterator eeeennnndddd() const; Returns an iterator positioned "just past" the last element in self. size_type eeeennnnttttrrrriiiieeeessss() const; Returns the number of items in self. float ffffiiiillllllllRRRRaaaattttiiiioooo() const; Returns the ratio eeeennnnttttrrrriiiieeeessss(((())))/ccccaaaappppaaaacccciiiittttyyyy(((()))). bool ffffiiiinnnndddd(const_reference a,T& k) const; If there exists an element tttt in self such that the expression ((((tttt ======== aaaa)))) is ttttrrrruuuueeee, assigns tttt to kkkk and returns ttttrrrruuuueeee. Otherwise, returns ffffaaaallllsssseeee and leaves the value of kkkk unchanged. bool ffffiiiinnnndddd(bool (*fn)(const_reference,void*),void* d,T& k) const; If there exists an element tttt in self that compares equal to aaaa, assigns tttt to kkkk and returns ttttrrrruuuueeee. Otherwise, returns ffffaaaallllsssseeee and leaves the value of kkkk unchanged. ffffnnnn points to a user-defined tester function which must have prototype: PPPPaaaaggggeeee 5555 RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhMMMMuuuullllttttiiiiSSSSeeeetttt((((3333CCCC++++++++)))) RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhMMMMuuuullllttttiiiiSSSSeeeetttt((((3333CCCC++++++++)))) bool yourTester(const_reference a, void* d); Client data may be passed through parameter dddd. bool iiiinnnnsssseeeerrrrtttt(const_reference a); Adds the item aaaa to the collection. Returns ttttrrrruuuueeee. void iiiinnnntttteeeerrrrsssseeeeccccttttiiiioooonnnn(const RWTValHashMultiSet<T,H,EQ>& s); Destructively performs a set theoretic intersection of self and ssss, replacing the contents of self with the result. bool iiiissssEEEEmmmmppppttttyyyy() const; Returns ttttrrrruuuueeee if there are no items in the collection, ffffaaaallllsssseeee otherwise. bool iiiissssEEEEqqqquuuuiiiivvvvaaaalllleeeennnntttt(const RWTValHashMultiSet<T,H,EQ>& s) const; Returns ttttrrrruuuueeee if there is set equivalence between self and ssss, and returns ffffaaaallllsssseeee otherwise. bool iiiissssPPPPrrrrooooppppeeeerrrrSSSSuuuubbbbsssseeeettttOOOOffff(const RWTValHashMultiSet<T,H,EQ>& s) const; Returns ttttrrrruuuueeee if self is a proper subset of ssss, and returns ffffaaaallllsssseeee otherwise. bool iiiissssSSSSuuuubbbbsssseeeettttOOOOffff(const RWTValHashMultiSet<T,H,EQ>& s) const; Returns ttttrrrruuuueeee if self is a subset of ssss, and returns ffffaaaallllsssseeee otherwise. size_type ooooccccccccuuuurrrrrrrreeeennnncccceeeessssOOOOffff(const_reference a) const; Returns the number of elements tttt in self that compares equal to aaaa. PPPPaaaaggggeeee 6666 RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhMMMMuuuullllttttiiiiSSSSeeeetttt((((3333CCCC++++++++)))) RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhMMMMuuuullllttttiiiiSSSSeeeetttt((((3333CCCC++++++++)))) size_type ooooccccccccuuuurrrrrrrreeeennnncccceeeessssOOOOffff(bool (*fn)(const_reference,void*),void* d) const; Returns the number of elements tttt in self such that the expression((((((((****ffffnnnn))))((((tttt,,,,dddd)))))))) is ttttrrrruuuueeee. ffffnnnn points to a user-defined tester function which must have prototype: bool yourTester(const_reference a, void* d); Client data may be passed through parameter dddd. bool rrrreeeemmmmoooovvvveeee(const_reference a); Removes the first element tttt in self that compares equal to aaaa and returns ttttrrrruuuueeee. Returns ffffaaaallllsssseeee if there is no such element. bool rrrreeeemmmmoooovvvveeee(bool (*fn)(const_reference,void*), void* d); Removes the first element tttt in self such that the expression ((((((((****ffffnnnn))))((((tttt,,,,dddd)))))))) is ttttrrrruuuueeee and returns ttttrrrruuuueeee. Returns ffffaaaallllsssseeee if there is no such element. ffffnnnn points to a user-defined tester function which must have prototype: bool yourTester(const_reference a, void* d); Client data may be passed through parameter dddd. size_type rrrreeeemmmmoooovvvveeeeAAAAllllllll(const_reference a); Removes all elements tttt in self that compare equal to aaaa. Returns the number of items removed. size_type rrrreeeemmmmoooovvvveeeeAAAAllllllll(bool (*fn)(const_reference,void*), void* d); PPPPaaaaggggeeee 7777 RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhMMMMuuuullllttttiiiiSSSSeeeetttt((((3333CCCC++++++++)))) RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhMMMMuuuullllttttiiiiSSSSeeeetttt((((3333CCCC++++++++)))) Removes all elements tttt in self such that the expression ((((((((****ffffnnnn))))((((tttt,,,,dddd))))))))is ttttrrrruuuueeee. Returns the number of items removed. ffffnnnn points to a user-defined tester function which must have prototype: bool yourTester(const_reference a, void* d); Client data may be passed through parameter dddd. void rrrreeeessssiiiizzzzeeee(size_type sz); Changes the capacity of self by creating a new hashed multi-set with a capacity of sssszzzz . rrrreeeessssiiiizzzzeeee copies every element of self into the new container and finally swaps the internal representation of the new container with the internal representation of sssseeeellllffff. rw_hashmultiset<T,H,EQ>& ssssttttdddd(); const rw_hashmultiset<T,H,EQ>& ssssttttdddd() const; Returns a reference to the underlying C++-standard collection that serves as the implementation for self. This reference may be used freely, providing access to the C++-standard interface as well as interoperability with other software components that make use of the C++-standard collections. void ssssyyyymmmmmmmmeeeettttrrrriiiiccccDDDDiiiiffffffffeeeerrrreeeennnncccceeee(const RWTValHashMultiSet<T,H,EQ>& s); Destructively performs a set theoretic symmetric difference operation on self and ssss. Self is replaced by the result. A symmetric difference can be informally defined as (A_B)-(A_B). void UUUUnnnniiiioooonnnn(const RWTValHashMultiSet<T,H,EQ>& rhs); Destructively performs a set theoretic union operation on self and rrrrhhhhssss. Self is replaced by the result. Note the uppercase "U" in UUUUnnnniiiioooonnnn to avoid PPPPaaaaggggeeee 8888 RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhMMMMuuuullllttttiiiiSSSSeeeetttt((((3333CCCC++++++++)))) RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhMMMMuuuullllttttiiiiSSSSeeeetttt((((3333CCCC++++++++)))) conflict with the C++ reserved word. RRRReeeellllaaaatttteeeedddd GGGGlllloooobbbbaaaallll OOOOppppeeeerrrraaaattttoooorrrrssss RWvostream& ooooppppeeeerrrraaaattttoooorrrr<<<<<<<<(RWvostream& strm, const RWTValHashMultiSet<T,H,EQ>& coll); RWFile& ooooppppeeeerrrraaaattttoooorrrr<<<<<<<<(RWFile& strm, const RWTValHashMultiSet<T,H,EQ>& coll); Saves the collection ccccoooollllllll onto the output stream ssssttttrrrrmmmm, or a reference to it if it has already been saved. RWvistream& ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(RWvistream& strm, RWTValHashMultiSet<T,H,EQ>& coll); RWFile& ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(RWFile& strm, RWTValHashMultiSet<T,H,EQ>& coll); Restores the contents of the collection ccccoooollllllll from the input stream ssssttttrrrrmmmm. RWvistream& ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(RWvistream& strm, RWTValHashMultiSet<T,H,EQ>*& p); RWFile& ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(RWFile& strm, RWTValHashMultiSet<T,H,EQ>*& p); Looks at the next object on the input stream ssssttttrrrrmmmm and either creates a new collection off the heap and sets pppp to point to it, or sets pppp to point to a previously read instance. If a collection is created off the heap, then you are responsible for deleting it. PPPPaaaaggggeeee 9999